<!-- 宠物健康信息 -->
<template>
    <div >
        <a-page-header
            style="border: 1px solid rgb(235, 237, 240);background:#fff"
            :title="'('+speciesName+')'+nickname+'的疫苗记录信息'"
            @back="() => $router.go(-1)"
        >
            <div class='table-page-search-wrapper'>
                <a-form layout='inline'>
                <a-row :gutter='48'>
                        <a-col :md="8" :sm="24">
                            <a-form-item label="疫苗名称">
                                <a-input v-model="name" allow-clear placeholder="请输入疫苗名称" />
                            </a-form-item>
                        </a-col>
                        <a-col :md="8" :sm="24">
                            <a-form-item label="接种时间">
                                <a-date-picker v-model="vaccinateTime" valueFormat="YYYY-MM-DD" format="YYYY-MM-DD" @change="getData"/>
                            </a-form-item>
                        </a-col>
                        <a-col :md='8' :sm='24'>
                            <a-form-item >
                                <a-button type='primary' @click="getData">查询</a-button>
                            </a-form-item>
                        </a-col>
                    </a-row>
                </a-form>
            </div>  

            <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange" :pagination="{ pageSize: 10, total: total ,showSizeChanger: true,pageSize: size, }" size="small">
                <div slot="remarks" slot-scope="remarks">
                    <ellipsis :length="18" tooltip>{{ remarks == '' || !remarks ? '-' : remarks }}</ellipsis>
                </div>
                <div slot="operation" slot-scope="text,record">
                    <a-button type="link" @click="update(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前配置?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link">删除</a-button>
                    </a-popconfirm>
                </div>
            </a-table>
        </a-page-header>
    </div>
</template>

<script>
import { queryPetVaccineRecord } from '@/api/pet';
import { columns } from './table';
import { Ellipsis } from '@/components';
export default {
    components: {
        Ellipsis,
    },
    data () {
        return {
            brandId: this.global.brandId,
            petId:this.$route.query.petId,
            speciesId:this.$route.query.speciesId,
            speciesName:this.$route.query.speciesName,
            nickname:this.$route.query.nickname,
            name: '', // 疫苗名称
            vaccinateTime: '', // 接种时间
            projectList: [], // 服务项目列表
            specList: [], // 宠物种类列表
            columns,
            colors: ['blue','purple','cyan','green','orange','red','pink','brown','indigo','lime','purple','teal','yellow','amber'],
            dataList: [],
            total: 0,
            isload: false,
            page: 1,
            size: 10,
        };
    },
    async created(){
        try {
            this.getData()
        } catch (error) {
            this.$notification['error']({
                message: '提示',
                description: error,
                duration: 8,
            })
        }
    },
    methods: {
        // 查询数据
        getData(){
            let _this = this
            _this.isload = true
            const params = {
                'brandId': _this.brandId,
                'petId': _this.petId,
                'name': _this.name,
                'vaccinateTime': _this.vaccinateTime,
                'size':_this.size,
                'page':_this.page - 1,
            }
            queryPetVaccineRecord(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data.content
                    _this.total = res.data.totalElements
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
    }
}

</script>
<style scoped>

</style>